package com.momoauth.common.core.handler;

import com.momoauth.common.core.exception.GlobalException;
import com.momoauth.common.core.result.ResponseResurt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 自定义全局异常
     * @param ge
     * @return
     */
    @ExceptionHandler(GlobalException.class)
    public ResponseResurt handleGlobalException(GlobalException ge) {
        log.error("GlobalException [code:{}, msg:{}]", ge.getCode(), ge.getMessage());
        return ResponseResurt.error().code(ge.getCode()).msg(ge.getMessage());
    }
}
